<template>
  <div class="video">
    <video ref="vPull" controls autoplay muted width="50%" height="50%"></video>
  </div>
</template>

<script>
import flv from "flv.js";
export default {
  name: "HelloWorld",
  data() {
    return {
      player: null,
    };
  },
  mounted() {
    this.play("http://47.100.121.5/live?port=1935&app=myapp&stream=test");
  },
  methods: {
    play(urls) {
      let video = this.$refs.vPull; //定义播放路径
      if (flv.isSupported()) {
        this.player = flv.createPlayer(
          {
            type: "flv",
            isLive: true,
            url: urls,
          },
          {
            enableWorker: false, //不启用分离线程
            enableStashBuffer: false, //关闭IO隐藏缓冲区
            isLive: true,
            lazyLoad: false,
          }
        );
      } else {
        console.log("不支持的格式");
        return;
      }
      this.player.attachMediaElement(video);
      this.player.load();
      this.player.play();
    },
    destruction() {
      //销毁对象
      if (this.player) {
        this.player.pause();
        this.player.destroy();
        this.player = null;
      }
    },
  },
};
</script>

<style>
</style>